import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';

export class AddChapterUrlAndVolumeFields1736429150000
  implements MigrationInterface
{
  name = 'AddChapterUrlAndVolumeFields1736429150000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.addColumn(
      'novel_chapters',
      new TableColumn({
        name: 'chapterUrl',
        type: 'varchar',
        length: '500',
        isNullable: true,
        comment: '章节URL',
      }),
    );

    await queryRunner.addColumn(
      'novel_chapters',
      new TableColumn({
        name: 'isFree',
        type: 'tinyint',
        default: 1,
        comment: '是否免费: 0-收费 1-免费',
      }),
    );

    await queryRunner.addColumn(
      'novel_chapters',
      new TableColumn({
        name: 'volumeName',
        type: 'varchar',
        length: '100',
        isNullable: true,
        comment: '卷名',
      }),
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropColumn('novel_chapters', 'chapterUrl');
    await queryRunner.dropColumn('novel_chapters', 'isFree');
    await queryRunner.dropColumn('novel_chapters', 'volumeName');
  }
}
